<?php

use think\Container;

if (!function_exists('getBuilderVersion')) {

    function getBuilderVersion()
    {
        return 'v4.0.3';
    }
}

if (!function_exists('addons_path')) {

    function addons_path($addon = '')
    {
        return app()->getRootPath() . 'addons' . DIRECTORY_SEPARATOR . $addon;
    }
}

if (!function_exists('builderView')) {

    /**
     * 获取BuilderView对象
     * @return \addons\BuilderPlus\driver\View
     */
    function builderView()
    {
        return Container::getInstance()->make(addons\BuilderPlus\driver\View::class);
    }
}

if (!function_exists('builderFormInit')) {


    function builderFormInit($options)
    {
        return builderView()->builderFormInit($options);
    }
}

if (!function_exists('getAttachMenu')) {

    function getAttachMenu()
    {
        $menu = [];
        if (env('APP_DEBUG') && request()->ip() === '127.0.0.1') {
            $menu[] = [
                'title'     => '插件管理',
                'sub_title' => '插件',
                'child'     => [
                    [
                        'href'  => url('addons/index')->build(),
                        'title' => '插件列表'
                    ],

                ]
            ];
        }
        if (env('APP_DEBUG') && config('tool')['task']) {
            $menu[] = [
                'title'     => '定时任务',
                'sub_title' => '定时',
                'child'     => [
                    [
                        'href'  => url('test/index')->build(),
                        'title' => '任务列表'
                    ],

                ]
            ];
        }
        return $menu;
    }
}
